package com.pig4cloud.pig.admin.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.admin.api.entity.PrUserRfidEntity;
import com.pig4cloud.pig.admin.service.PrUserRfidService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 用户rfid中间表
 *
 * @author pig
 * @date 2025-06-14 21:36:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/prUserRfid" )
@Tag(description = "prUserRfid" , name = "用户rfid中间表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PrUserRfidController {

    private final  PrUserRfidService prUserRfidService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param prUserRfid 用户rfid中间表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getPrUserRfidPage(@ParameterObject Page page, @ParameterObject PrUserRfidEntity prUserRfid) {
        LambdaQueryWrapper<PrUserRfidEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(prUserRfidService.page(page, wrapper));
    }


    /**
     * 通过条件查询用户rfid中间表
     * @param prUserRfid 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject PrUserRfidEntity prUserRfid) {
        return R.ok(prUserRfidService.list(Wrappers.query(prUserRfid)));
    }

    /**
     * 新增用户rfid中间表
     * @param prUserRfid 用户rfid中间表
     * @return R
     */
    @Operation(summary = "新增用户rfid中间表" , description = "新增用户rfid中间表" )
    @SysLog("新增用户rfid中间表" )
    @PreAuthorize("@pms.hasPermission('admin_prRfid_add')" )
    @PostMapping
    public R save(@RequestBody PrUserRfidEntity prUserRfid) {
        return R.ok(prUserRfidService.save(prUserRfid));
    }

    /**
     * 修改用户rfid中间表
     * @param prUserRfid 用户rfid中间表
     * @return R
     */
    @Operation(summary = "修改用户rfid中间表" , description = "修改用户rfid中间表" )
    @SysLog("修改用户rfid中间表" )
    @PutMapping
    public R updateById(@RequestBody PrUserRfidEntity prUserRfid) {
        return R.ok(prUserRfidService.updateById(prUserRfid));
    }

    /**
     * 通过id删除用户rfid中间表
     * @param ids userId列表
     * @return R
     */
    @Operation(summary = "通过id删除用户rfid中间表" , description = "通过id删除用户rfid中间表" )
    @SysLog("通过id删除用户rfid中间表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(prUserRfidService.removeBatchByIds(CollUtil.toList(ids)));
    }
    /**
     * 通过id删除rfid用户中间表
     * @param prUserRfidEntity ${pk.attrName}列表
     * @return R
     */
    @Operation(summary = "通过id删除设备单位中间表" , description = "通过id删除rfid用户中间表" )
    @SysLog("通过id删除设备单位中间表" )
    @PreAuthorize("@pms.hasPermission('admin_prRfid_del')" )
    @PostMapping("remove")
    public R remove(@RequestBody PrUserRfidEntity prUserRfidEntity) {
        return R.ok(prUserRfidService.remove(new LambdaQueryWrapper<PrUserRfidEntity>().eq(PrUserRfidEntity::getRfidId,prUserRfidEntity.getRfidId()).eq(PrUserRfidEntity::getUserId,prUserRfidEntity.getUserId())));
    }


}
